<!doctype html>
<html lang="en">
<head>
    <title>ComboBox - Remote Data</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="description" content="%description%" />
    <meta name="keywords" content="" />
    <meta name="author" content="ComponentOne" />
    <link href="../base-reset.css" rel="stylesheet" type="text/css" />
    <link href="../../themes/Aristo/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css" />
    <link href="../demos-single.css" rel="stylesheet" type="text/css" />
    <script src="../../external/jquery-1.4.3.min.js" type="text/javascript"></script>
    <script src="../../external/jquery-ui-1.8.6.custom.min.js" type="text/javascript"></script>
    <link href="../../themes/wijmo/jquery.wijmo-open.0.8.2.css" rel="stylesheet" type="text/css" />
    <link href="../../themes/wijmo/jquery.ui.wijcombobox.css" rel="stylesheet" type="text/css" />
    <script src="../../external/jquery.mousewheel.min.js" type="text/javascript"></script>
    <script src="../../external/jquery.wijmo-open.0.8.2.min.js" type="text/javascript"></script>
    <script src="../../wijmo/jquery.ui.wijdatasource.js" type="text/javascript"></script>
    <script src="../../wijmo/jquery.ui.wijcombobox.js" type="text/javascript"></script>
    <script id="scriptInit" type="text/javascript">
        $(document).ready(function () {
            var proxy = new wijhttpproxy({
                url: "http://ws.geonames.org/searchJSON",
                dataType: "jsonp",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12
                },
                key: 'geonames'
            });

            var myReader = new wijarrayreader([{
                name: 'label',
                mapping: function (item) {
                    return item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName
                }
            }, {
                name: 'value',
                mapping: 'name'
            }, {
                name: 'selected',
                defaultValue: false
            }]);


            var datasource = new wijdatasource({
                reader: myReader,
                proxy: proxy
            });
            $("#tags").wijcombobox({
                data: datasource,
                showTrigger: false,
                search: function (e, obj) {
                    obj.datasrc.proxy.options.data.name_startsWith = obj.term.value;
                },
                select: function (e, item) {
                    $('#output').html('I come from ' + item.label + '!');
                }
            });
        });
            
            
    </script>
</head>
<body class="demo-single">
    <div class="container">
        <div class="header">
            <h2>
                Remote Data</h2>
        </div>
        <div class="main demo">
            <!-- Begin demo markup -->
                <label for="tags">
                    Type 4 chars to lookup a city</label>
                <input id="tags" style="width: 300px" />
                <p>
                    <label id="output">
                    </label>
                </p>
            <!-- End demo markup -->
            <div class="demo-options">
                <!-- Begin options markup -->
                <!-- End options markup -->
            </div>
        </div>
        <div class="footer demo-description">
            <p>
            </p>
        </div>
    </div>
</body>
</html>
